package com.leyou.item.controller;

import com.leyou.item.dto.SpecGroupDTO;
import com.leyou.item.dto.SpecParamDTO;
import com.leyou.item.service.SpecService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author syf
 * @version 1.0
 * @date 2019/08/02 16:27
 * @Description TODO:规格控制器
 */
@RestController
@RequestMapping("/spec")
public class SpecController {

    @Autowired
    private SpecService specService;

    /**
     * 查询规格组信息
     * @param id
     * @return
     */
    @GetMapping("/groups/of/category")
    public ResponseEntity<List<SpecGroupDTO>> findGroupByCid(@RequestParam("id") Long id){
        return ResponseEntity.ok(specService.findGroupByCid(id));
    }

    /**
     * 查询规格参数信息
     * @return
     */
    @GetMapping("/params")
    public ResponseEntity<List<SpecParamDTO>> findParams(@RequestParam(value = "gid",required = false)Long gid,
                                                         @RequestParam(value = "cid",required = false)Long cid,
                                                         @RequestParam(value = "searching",required = false) Boolean searching
                                                        ){
        return ResponseEntity.ok(specService.findParams(gid,cid,searching));

    }

    //根据categoryId查询规格参数组和组内参数
    @GetMapping("/of/category")
    public ResponseEntity<List<SpecGroupDTO>> findGroupByCidWithParams(@RequestParam("id") Long id){
        return ResponseEntity.ok(specService.findGroupByCidWithParams(id));
    }
}
